
'''
https://leetcode.cn/problems/intersection-of-two-arrays/description/
https://programmercarl.com/0349.%E4%B8%A4%E4%B8%AA%E6%95%B0%E7%BB%84%E7%9A%84%E4%BA%A4%E9%9B%86.html#%E7%AE%97%E6%B3%95%E5%85%AC%E5%BC%80%E8%AF%BE
两个数组的交集
nums1=[1,2,2,1] nums2=[2,2] 交集[2]
'''


def l349(nums1 ,nums2) :
    d1 = {}
    res = set()
    r = []
    for i in nums1:
        d1[i] = 1
    for i in nums2:
        if d1.get(i):
            res.add(i)
    for i in res:
        r.append(i)
    return r

def l349_1(nums1 ,nums2) :
    d1 = set(nums1)
    d2 = set(nums2)
    res = []
    for i in d1:
        if i in d2:res.append(i)
    return res


if __name__ == '__main__':
    print(l349([1,2,2,1],[2,2,3]))
    print(l349_1([4,9,4,5,5],[9,4,9,8,4]))
    pass